{% extends './layout.html' %} {% block title %} {{ title }} {% endblock %}{% block crumbs %}
<a href="/">首页</a>
<a><cite>管理员管理</cite></a>
{% endblock %}{% block body %}
<div class="layout_head">
	<button type="button" class="layui-btn layui-btn-sm" data-method="create"><i class="layui-icon">&#xe608;</i> 新增管理员</button>
</div>
<div class="layout_cont">
	<table class="layui-table">
		<colgroup>
			<col width="60">
			<col>
			<col>
			<col>
			<col>
			<col width="200">
			<col width="110">
		</colgroup>
		<thead>
			<tr>
				<th>序号</th>
				<th>用户名</th>
				<th>昵称</th>
				<th>电子邮箱</th>
				<th>登录IP</th>
				<th>登录时间</th>
				<th>操作</th>
			</tr>
		</thead>
		<tbody>
			{% for item in list %}
			<tr>
				<td>{{ item.id }}</td>
				<td>{{ item.username }}</td>
				<td>{{ item.nickname }}</td>
				<td>{{ item.email }}</td>
				<td>{{ item.loginip }}</td>
				<td>{{ item.logintime | date('Y-m-d h:m:s') }}</td>
				<td style="font-size: 0;">
					<button type="button" class="layui-btn layui-btn-xs layui-btn-warm" data-method="update" data-id="{{item.id}}">编辑</button>
					<button type="button" class="layui-btn layui-btn-xs layui-btn-danger" data-method="delete" data-id="{{item.id}}" }>删除</button>
				</td>
			</tr>
			{%- endfor %}
		</tbody>
	</table>
</div>
{% endblock %} {% block template %}
<script id="adminForm" type="text/html">
	<form class="layui-form layout_form" lay-filter="adminForm">
		<div class="layui-form-item">
			<label class="layui-form-label">用户名</label>
			<div class="layui-input-block">
				<input type="text" name="username" lay-verify="required" lay-reqtext="用户名是必填项，岂能为空？" placeholder="请输入用户名" autocomplete="off" class="layui-input">
			</div>
		</div>
		<div class="layui-form-item">
			<label class="layui-form-label">密码</label>
			<div class="layui-input-block">
				<input type="password" name="userpass" lay-verify="required" lay-reqtext="密码是必填项，岂能为空？" placeholder="请输入密码" autocomplete="off" class="layui-input">
			</div>
		</div>
		<div class="layui-form-item">
			<label class="layui-form-label">确认密码</label>
			<div class="layui-input-block">
				<input type="password" name="userpass2" lay-verify="required" lay-reqtext="密码是必填项，岂能为空？" placeholder="请在一次确认密码" autocomplete="off" class="layui-input">
			</div>
		</div>
		<div class="layui-form-item">
			<label class="layui-form-label">昵称</label>
			<div class="layui-input-block">
				<input type="text" name="realname" lay-verify="required" lay-reqtext="昵称是必填项，岂能为空？" placeholder="请输入昵称" autocomplete="off" class="layui-input">
			</div>
		</div>
		<div class="layui-form-item">
			<label class="layui-form-label">邮箱</label>
			<div class="layui-input-block">
				<input type="text" name="email" lay-verify="email" placeholder="请输入邮箱" autocomplete="off" class="layui-input">
			</div>
		</div>

		<div class="layui-form-item">
			<label class="layui-form-label">验证身份证</label>
			<div class="layui-input-block">
				<input type="text" name="identity" lay-verify="identity" placeholder="" autocomplete="off" class="layui-input">
			</div>
		</div>
		<div class="layui-form-item">
			<div class="layui-input-block">
				<button type="submit" class="layui-btn" lay-submit lay-filter="add">立即提交</button>
				<button type="button" class="layui-btn layui-btn-primary" lay-filter="reset">重置</button>
			</div>
		</div>
	</form>
</script>
{% endblock %} {% block scripts %}
<script type="text/javascript">
	layui.use(['layer', 'form'], function() {
		var $ = layui.jquery;
		var layer = layui.layer;
		var laytpl = layui.laytpl;
		var form = layui.form;
		var adminMethod = {
			create: function() {
				var index = layer.open({
					type: 1,
					title: '添加管理员',
					area: ['540px', 'auto'],
					content: $('#adminForm').html()
				});
				form.on('submit(add)', function(data) {
					console.log(data.field);
					//layer.close(index);
					return false;
				})
				form.on('button(reset)', function(data) {
					form.render();
					layer.close(index);
				})
			},
			update: function() {
				var id = $(this).data('id');
				var index = layer.open({
					type: 1,
					title: '修改管理员',
					area: ['540px', 'auto'],
					content: $('#adminForm').html()
				});
			},
			delete: function() {
				var id = $(this).data('id');
				layer.confirm('是否删除当前管理员？', {
					btnAlign: 'c',
					title: '删除确认'
				}, function(index) {
					console.log(this);
					layer.close(index);
				});
			}
		}
		$('.layui-btn').on('click', function() {
			var method = $(this).data('method');
			if(adminMethod[method]) {
				adminMethod[method].call(this)
			}
		});
		//layer.msg('删除成功');
	});
</script>
{% endblock %}